package com.dynaBlaster.core;

public class Point {
	public int x;
	public int y;

	static public Point ZERO = new Point();

	static final int[] COS = new int[] { 1, 0, -1, 0 };
	static final int[] SIN = new int[] { 0, 1, 0, -1 };

	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public Point(Point other) {
		x = other.x;
		y = other.y;
	}

	public Point() {
		x = 0;
		y = 0;
	}



	final public void set(Point other) {
		x = other.x;
		y = other.y;
	}

	final public Point add(Point other) {
		return new Point(x + other.x, y + other.y);
	}

	final public Point sub(Point other) {
		return new Point(x - other.x, y - other.y);
	}

	final public Point mul(int mult) {
		return new Point(x * mult, y * mult);
	}

	final public Point divint(int divi) {
		return new Point(x / divi, y / divi);
	}

	final public int mag2() {
		return x * x + y * y;
	}

	final public int dist2(Point other) {
		return this.sub(other).mag2(); // kwadrat dlugosci this w ukladzie other
	}

	final public boolean eq(Point other) {
		return x == other.x && y == other.y;
	}

	final public Point projX() {
		return new Point(x, 0);
	}

	final public Point projY() {
		return new Point(0, y);
	}

	final public int dot(Point other) {
		return x * other.x + y * other.y;
	}

	final public int cross2(Point other) {
		return x * other.y - other.x * y;
	}

	final public Point rotate(int sin, int cos) {
		return new Point(x * cos - y * sin, x * sin + y * cos);
	}

	final public Point rotate90(int n) {

		int i = ((n % 4) + 4) % 4;

		return rotate(SIN[i], COS[i]);
	}

	public boolean nonzero() {
		return x != 0 || y != 0;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Point other = (Point) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "point: [" + x + ", " + y + "]";
	}

}
